package com.zhongying.jf.sms.liulangmao;


import org.apache.log4j.Logger;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class Post {

    private final static Logger logger = Logger.getLogger(Post.class);
    /**
	 * 发送短信接口，可以多条短信
	 * @author hq
	 * @param app_key 	
	 * @param app_secret  
	 * @param nonce_str 用户名
	 * @param dest_id   手机号，   多个的时候用, （英文逗号） 隔开
	 * @param title 	签名
	 * @param content 	内容
	 * 
	 */
	public String getPost(String app_key,String app_secret,String nonce_str,
                        String dest_id,String title,String content) {
        try {
        	String shrot_message="http://api.5iliulang.com/api/v1/manySend";
            URL url = new URL(shrot_message);
            URLConnection con = url.openConnection();
            con.setDoOutput(true);
            //con.setRequestProperty("Pragma:", "no-cache");
            con.setRequestProperty("Cache-Control", "no-cache");
            con.setRequestProperty("Content-Type", "text/xml");
            con.setRequestProperty("charset", "UTF-8");
            //
            OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream(),"UTF-8");
            GetXmlInfo xml=new GetXmlInfo();
            String xmlInfo = xml.getXmlInfo( app_key,app_secret,nonce_str,dest_id,title,content);
            System.out.println("urlStr=" + shrot_message);
            System.out.println("xmlInfo=" + xmlInfo);
            out.write(new String(xmlInfo.getBytes("UTF-8"),"UTF-8"));
            out.flush();
            out.close();
            BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
            String line = "";
            String body= "";
            for (line = br.readLine(); line != null; line = br.readLine()) {
                body+=line;
            }
            System.out.println(body);
            return body;
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
